package app

import (
	"fmt"
	"gitee.com/yysf-xin/dproxy/pkg/tools"
	"github.com/go-chi/chi/v5"
)

const CtxPath = "/dproxy/"

// Service 服务抽象接口
type Service interface {
	fmt.Stringer
}

type Lifestyle interface {
	Start() error
	Stop()
}

type Services struct {
	l tools.List
}

type RouterProver interface {
	RouteName() string
}

type InitRouter interface {
	InitRoute(router chi.Router)
}

func NewServices() (s *Services) {
	s = new(Services)
	//s = &Services{
	//	Api: chi.NewRouter(),
	//	Server: chi.NewRouter(),
	//}
	//s.Server.Mount(CtxPath,s.Api)
	s.l.Init()
	return
}

func (s *Services) AddService(svr Service) {
	tools.Log.Println("add service", svr)
	s.l.Add(svr)
}

func (s *Services) RemoveService(svr Service) {
	s.l.Remove(svr)
	tools.Log.Println("remove service", svr)
}

func (s *Services) GetService(name string) Service {
	if sv, ok := s.l.GetByString(name).(Service); ok {
		return sv
	}
	return nil
}

type Modeler interface {
	GetId() uint
	TableName() string
}

type StateChanger interface {
	Change(status int)
}
